#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static constexpr int MAX_NODE =  5050;


int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k; cin >> n >> k;
    vector<pii> vp(k);
    for (int i = 0; i < k; i++) cin >> vp[i].first >> vp[i].second;
    sort(vp.begin(), vp.end());
    vector<int> dp(n + 2, 0);
    int index = k - 1;
    int max_val = 0;
    for (int i = n; i >= 1; i--)
    {
        if (index >= 0 && vp[index].first == i)
        {
            while (index >= 0 && vp[index].first == i)
            {
                dp[i] = max(dp[i], dp[i + vp[index].second]);
                --index;
            }
        }
        else dp[i] = dp[i + 1] + 1;
    }
    cout << dp[1];
    return 0;
}














